//输入框最大长度限制
const inputMaxLength = {
  default: 30,
  textarea: 150,
  phone: 11
};

const maxLength = {
  mounted(el, binding) {
    const { value } = binding;
    let len = value ? inputMaxLength[value] : inputMaxLength["default"];
    // 获取dom下input标签，设置最大长度
    setLength(el, len, "input");
    setLength(el, len, "textarea");
  }
};
const setLength = (el, len, tagName) => {
  let domList = el.getElementsByTagName(tagName);
  for (let i = 0; i < domList.length; i++) {
    domList[i].setAttribute("maxlength", len);
  }
};

const setMaxLength = (app) => {
  app.directive("maxLength", maxLength);
};

export default setMaxLength;
